#include "admin.h"
#include "adminlogin.h"
#include "q_login.h"
#include "system.h"
#include "ui_system.h"
#include <QMessageBox>

System::System(QWidget* parent) :
    QWidget(parent),
    ui(new Ui::System)
{
    ui->setupUi(this);
    m_tcpserver = new QTcpServer(this);
    m_tcpsocket = new QTcpSocket(this);

    int port = 8010;
    m_tcpserver->listen(QHostAddress::Any, port);
    connect(m_tcpserver, SIGNAL(newConnection()), this, SLOT(newConnection_Slot()));
}
void System::newConnection_Slot()
{
    QMessageBox::warning(this, "连接成功", "有人正在填写问卷！");
    m_tcpsocket = m_tcpserver->nextPendingConnection();
    connect(m_tcpsocket, &QTcpSocket::readyRead, this, &System::readyRead_Slot);
}
void System::readyRead_Slot()
{
    ui->textEdit->append(m_tcpsocket->readAll());

}

System::~System()
{
    delete ui;

}

void System::on_pushButtonAdmin_clicked()
{
    AdminLogin* m = new AdminLogin();
    m->show();
    this->close();
}

void System::on_pushButtonWenjuan_clicked()
{
    Q_login* m = new Q_login();
    m->show();
    this->close();
}
